From: Joey Hess Date: Wed, 29 Jan 2025 18:06:54 +0000 (-0400) Subject: fix toOsPath on windows X-Git-Tag: archive/raspbian/10.20250416-2+rpi1~1^2~6^2~183^2~8 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:///%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:/?a=commitdiff_plain;h=9c9baf7c6581235643661b94f70f76f8a10ae60e;p=git-annex.git fix toOsPath on windows After recent changes to use OsPath, test suite fails on windows with: Exception: Uneven number of bytes: 5. This is not a Word16 bytestream. Hopefully this fixes it. The innefficiency of the conversion is unfortunate. --- diff --git a/Utility/OsPath.hs b/Utility/OsPath.hs index 5a62e61004..bd7baf85eb 100644 --- a/Utility/OsPath.hs +++ b/Utility/OsPath.hs @@ -22,13 +22,16 @@ import Utility.FileSystemEncoding import System.OsPath import "os-string" System.OsString.Internal.Types import qualified Data.ByteString.Short as S +#if defined(mingw32_HOST_OS) +import GHC.IO (unsafePerformIO) +#endif -{- Unlike System.OsString.fromBytes, on Windows this does not ensure a - - valid USC-2LE encoding. The input ByteString must be in a valid encoding - - already or uses of the OsPath will fail. -} toOsPath :: RawFilePath -> OsPath #if defined(mingw32_HOST_OS) -toOsPath = OsString . WindowsString . S.toShort +-- On Windows, OsString contains a ShortByteString that is +-- utf-16 encoded. So have to convert the input to that. +-- This is relatively expensive. +toOsPath = unsafePerformIO . encodeFS . fromRawFilePath #else toOsPath = OsString . PosixString . S.toShort #endif